package zhihui.mobile.ui.register;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.zgm.utils.UiUtils;

import zhihui.mobile.R;
import zhihui.mobile.presenter.IPresenter;
import zhihui.mobile.presenter.register.IPhoneFragmentContract;
import zhihui.mobile.presenter.register.PhoneFragmentPresenter;
import zhihui.mobile.presenter.register.RegisterPersenter;
import zhihui.mobile.ui.BaseFragment;

/**
 * Created by 张公铭 on 2017/7/8 0008.
 */

public class PhoneFragment extends BaseFragment implements IPhoneFragmentContract.IPhoneFragmentView
{
    private IPhoneFragmentContract.IPhoneFragmentPersenter persenter = new PhoneFragmentPresenter();
    private EditText ed_phone;
    private Button btn_next;
    private RegisterPersenter registerPersenter;
    private TextView tv_msg;

    public void setRegisterPersenter(RegisterPersenter registerPersenter)
    {
        this.registerPersenter = registerPersenter;
    }

    @Override
    protected int getLayoutResId()
    {
        return R.layout.register_phone_fragment;
    }

    @Override
    protected IPresenter[] getPresenters()
    {
        return new IPresenter[]{ persenter};
    }

    @Override
    protected void onInitPresenter()
    {
        persenter.init(this, getContext());
    }

    @Override
    public void initView()
    {
        ed_phone = (EditText) mView.findViewById(R.id.ed_register_phone);
        UiUtils.editTextFocus(ed_phone);
        btn_next = (Button) mView.findViewById(R.id.btn_register_phone_next);
        btn_next.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                tv_msg.setText("");
                persenter.goPhoneCodeFragment(ed_phone.getText().toString());
            }
        });
        tv_msg = (TextView) mView.findViewById(R.id.tv_phone_msg);
        tv_msg.setText("");
    }

    @Override
    public void goPhoneCodeFragment()
    {
        registerPersenter.showPhoneCodeFragment();
    }

    @Override
    public void initPhone(String phone)
    {
        ed_phone.setText(phone);
        UiUtils.editTextFocus(ed_phone);
    }

    @Override
    public void showMessage(String message)
    {
        tv_msg.setText(message);
    }
}
